package ca.cbc.msb.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AppConfig {
	private static Logger log = LoggerFactory.getLogger(AppConfig.class);
    private static Properties properties;
    
    public static String getProperty(String key) {
        if (properties == null) {
            synchronized (AppConfig.class) {
                if (properties == null) {
                    InputStream is = null;
                    try {

                        // load properties
                        is = AppConfig.class.getClassLoader().getResourceAsStream("msb.properties");
                        if (is == null) {
                            throw new FileNotFoundException("msb.properties not found");

                        }

                        properties = new Properties();
                        properties.load(is);
                    } catch (IOException e) {
                        log.error("Error reading properties ", e);
                    } finally {
                        try {
                            assert is != null;
                            is.close();
                        } catch (IOException e) {
                            log.error("Could not close file handler for property file", e);
                        }
                    }
                }
            }
        }
        return properties.getProperty(key);

    }
}

